using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections.Specialized;

namespace WroxControls 
{

	// This control renders out three root element HTML elements and thus
	// overrides the Render method
	
   public class MyTextBox : WebControl,
								    IPostBackDataHandler
   {
		
   	public MyTextBox() : base ("input")
		{
		}


		public event EventHandler TextChanged;

		string _value;

		public string Text
      {
         get { return _value; }
      }
		
		protected override void AddAttributesToRender(HtmlTextWriter writer)
		{
				base.AddAttributesToRender(writer);
            writer.AddAttribute(HtmlTextWriterAttribute.Name, UniqueID);

            writer.AddAttribute(HtmlTextWriterAttribute.Type, "input" );
				if ( _value != null )
					writer.AddAttribute( "value", _value );
		}

      bool IPostBackDataHandler.LoadPostData(string postDataKey, NameValueCollection postCollection) 
		{
			_value = postCollection[postDataKey];

			return true;
		}

		void IPostBackDataHandler.RaisePostDataChangedEvent() 
		{

			if ( TextChanged != null )
				TextChanged( this, EventArgs.Empty );

      }

   }
};
